package com.gxuwz.attendance.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
/**
 * json数据的转换工具
 * @author 蔡奇峰
 *
 */
public class JsonUtil {

	public static void toJons(HttpServletResponse response, Object obj) {
		
		Gson son = new Gson();
		String result = son.toJson(obj);
		response.setContentType("text/json; charset=utf-8");
		response.setHeader("Cache-Control", "no-cache"); //取消浏览器缓存
		PrintWriter write;
		try {
			System.out.println("result:" + result);
			write = response.getWriter();
			write.print(result);
			write.flush();
			write.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
}
